package com.mobi.Survey.lib.model;

import android.content.Context;

import com.mobi.Survey.lib.db.AbstractTable;
import com.mobi.Survey.lib.db.SubscriptionTable;

/**
 * 
 * <b>Author:</b> Yahya Arshad
 * <p>
 * <b>Company:</b> Mobi Media Soft
 * <p>
 * <b> Website:</b> www.mobimediasoft.com
 * <p>
 * SubscriptionPojo.java This class holds Survey's subscription detail
 */
public class SubscriptionPojo extends Pojo
{
	private int id;
	private long subsId;
	private String fName;
	private String lName;
	private String email;
	public int getId()
	{
		return id;
	}


	
	public long getSubsId()
	{
		return subsId;
	}

	public String getfName()
	{
		return fName;
	}

	public String getlName()
	{
		return lName;
	}

	public String getEmail()
	{
		return email;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public void setSubsId(long subsId)
	{
		this.subsId = subsId;
	}

	public void setfName(String fName)
	{
		this.fName = fName;
	}

	public void setlName(String lName)
	{
		this.lName = lName;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	/**
	 * 
	 * Is data of subscription null
	 * 
	 * @return
	 */
	public boolean isNull()
	{
		// email is't part of this check because Mobi media said don't include
		// it
		return (lName == null && fName == null);
	}

	/**
	 * 
	 * @param context
	 * @return if subscription data already exist in database or not
	 */
	public boolean isNew(Context context)
	{
		boolean is = false;

		SubscriptionTable at = new SubscriptionTable(context);
		try
		{
			is = at.isNewSubscription(subsId);
		} catch (Exception e)
		{
			e.printStackTrace();
		} finally
		{
			if (at != null)
			{
				at.closeDB();
				at = null;
			}

		}
		return is;

	}

	/**
	 * 
	 * @param ctx
	 * @param sp
	 *            SubscripitonPojo to save
	 * @return true if success
	 */
	public static boolean commit(Context ctx, SubscriptionPojo sp)
	{
		AbstractTable at = new SubscriptionTable(ctx);
		boolean is = false;
		if (sp != null && sp.isNew(ctx))
		{
			try
			{
				if (at.insertRow(sp) > 0)
				{
					is = true;
					//printConsoleMsg(" SubscriptionPojo Class: Subscription Row Added ");
				} else
				{
					//printConsoleMsg(" SubscriptionPojo Class: Duplicate Row ");
				}

			} catch (Exception e)
			{
				e.printStackTrace();
			} finally
			{
				 
					at.closeDB();
			}
		}
		return is;

	}

}
